package exam.demo1;

public class Test5 {

    public static int LastRemaining_Solution (int n, int m)
    {
        int f = 0;
        for(int i = 2; i <= n; i++) {
            f = (f + m) % i;
        }
        return f;
    }

    public static void main(String[] args) {

        int a = LastRemaining_Solution(5, 3);
        System.out.println(a);

    }
}
